package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsCommentMapper;
import com.qf.pojo.DtsComment;
import com.qf.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    private DtsCommentMapper dtsCommentMapper;

    @Override
    public IPage<DtsComment> findListByQuery(Integer page, Integer limit, Integer valueId, Integer userId, String sort, String order) {
       return dtsCommentMapper.selectPage(new Page<>(page,limit),new QueryWrapper<DtsComment>()
               .eq(userId!=null,"user_id",userId)
               .eq(valueId!=null,"value_id",valueId)
               .eq("deleted",false)
               .orderBy(!StringUtils.isEmpty(sort),"ASC".equalsIgnoreCase(order),sort));
    }

    @Override
    public void deleteComment(Integer id) {
        dtsCommentMapper.updateDeletedTrue(id);
    }
}
